package com.jiandaoshou.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.andview.refreshview.recyclerview.BaseRecyclerAdapter;
import com.jiandaoshou.R;
import com.jiandaoshou.entry.DingDanDetailEntry;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import static com.jiandaoshou.R.id.tv_wx_pay_price;


/**
 * Created by Administrator on 2016/9/28.
 */

public class DingDanRecyclerAdapter extends BaseRecyclerAdapter<DingDanRecyclerAdapter.MyViewHolder> {
    private List<DingDanDetailEntry> mDatas;
    private Context context;
    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");

    public DingDanRecyclerAdapter(Context context, List<DingDanDetailEntry> mDatas) {
        this.mDatas = mDatas;
        this.context = context;
    }



    @Override
    public MyViewHolder getViewHolder(View view) {
        return new MyViewHolder(view);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        switch (viewType) {
            case 1:
                View view = LayoutInflater.from(context).inflate(R.layout.item_header, parent, false);

            case 2:
                break;
        }
        View view = LayoutInflater.from(context).inflate(R.layout.item_child, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position, boolean isItem) {

        holder.Tv_name.setText(mDatas.get(position).getStrShopSonName());
        holder.Tv_price.setText(mDatas.get(position).getnTradingAmount() + "元");
        if (mDatas.get(position).getStrPaymentMode().equals(String.valueOf(1))) {
            holder.tv_pay_type.setText("微信支付");
        } else if (mDatas.get(position).getStrPaymentMode().equals(String.valueOf(2))) {
            holder.tv_pay_type.setText("支付宝支付");
        }

        try {
            Date date = format.parse(mDatas.get(position).getDtCreateTime());
            holder.Tv_data.setText(format1.format(date));
        } catch (Exception e) {
            holder.Tv_data.setText(mDatas.get(position).getDtCreateTime());
        }

        if (listener != null) {
            holder.itemView.setOnClickListener(view -> listener.OnClickListener(holder.getLayoutPosition(), holder.Item_View));
        }
    }

    @Override
    public int getAdapterItemViewType(int position) {
        if (position == 1) {
            return 1;
        } else {
            return 2;
        }

    }

    @Override
    public int getAdapterItemCount() {
        return mDatas.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView Tv_name;
        TextView Tv_data;
        TextView Tv_price;
        TextView tv_pay_type;
        View Item_View;

        public MyViewHolder(View view) {
            super(view);
            this.Item_View = view;
            Tv_name = (TextView) view.findViewById(R.id.tv_name);
            Tv_data = (TextView) view.findViewById(R.id.tv_time);
            Tv_price = (TextView) view.findViewById(R.id.tv_price);
            tv_pay_type = (TextView) view.findViewById(R.id.tv_pay_type);
        }
    }

    class MyHeaderViewHolder extends RecyclerView.ViewHolder {
        TextView Tv_ali_pay_num;
        TextView Tv_ali_pay_price;
        TextView Tv_wx_pay_num;
        TextView Tv_wx_pay_price;


        public MyHeaderViewHolder(View view) {
            super(view);
            Tv_ali_pay_num = (TextView) view.findViewById(R.id.tv_ali_pay_num);
            Tv_ali_pay_price = (TextView) view.findViewById(R.id.tv_ali_pay_price);
            Tv_wx_pay_num = (TextView) view.findViewById(R.id.tv_wx_pay_num);
            Tv_wx_pay_price = (TextView) view.findViewById(tv_wx_pay_price);
        }
    }

    private OnItemListener listener;

    public void setOnItemListener(OnItemListener listener) {
        this.listener = listener;
    }

    public interface OnItemListener {
        void OnClickListener(int pos, View view);
    }
}
